package com.oj.system.controller.sysuser;

import com.oj.common.core.constants.HttpConstants;
import com.oj.common.core.controller.BaseController;
import com.oj.common.core.domain.R;
import com.oj.common.core.domain.vo.LoginUserVO;
import com.oj.system.domain.sysuser.dto.LoginDTO;
import com.oj.system.domain.sysuser.dto.SysUserSaveDTO;
import com.oj.system.domain.sysuser.vo.SysUserVO;
import com.oj.system.service.sysuser.impl.SysUserServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author bin
 * @Date 2025/4/2
 */
@RestController
@RequestMapping("/sysUser")
@Tag(name = "管理员Api")
public class SysUserController extends BaseController {

    @Autowired
    private SysUserServiceImpl sysUserService;


    @PostMapping("/login")
    @Operation(summary = "管理员用户登录",description = "根据用户名，密码进行登录")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    @ApiResponse(responseCode = "3103", description = "用户名或密码错误")
    public R<String> login(@RequestBody @Validated LoginDTO loginDTO) {
        return sysUserService.login(loginDTO.getUserAccount(),loginDTO.getPassword());
    }


    @PostMapping("/add")
    @Operation(summary = "新增管理员用户",description = "根据提供的用户名，密码添加管理员用户")
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3101", description = "用户已存在")
    public R<Void> add(@RequestBody @Validated SysUserSaveDTO sysUserSaveDTO){
        return toR(sysUserService.add(sysUserSaveDTO));
    }

    @DeleteMapping("/{userId}")
    @Operation(summary = "删除管理员用户",description = "根据提供的用户Id删除管理员用户")
    @Parameters({
            @Parameter(name = "userId", in = ParameterIn.PATH ,description = "用户Id", required = true)
    })
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    public R<Void> delete(@PathVariable Long userId){
        return null;
    }

    @GetMapping("/detail")
    @Operation(summary = "查询管理员用户详细信息",description = "根据提供的条件查询用户详情")
    @Parameters({
            @Parameter(name = "userId", in = ParameterIn.QUERY ,description = "用户Id", required = true),
            @Parameter(name = "sex", in = ParameterIn.QUERY ,description = "用户性别", required = false)
    })
    @ApiResponse(responseCode = "1000", description = "操作成功")
    @ApiResponse(responseCode = "2000", description = "服务器繁忙,请稍后重试")
    @ApiResponse(responseCode = "3102", description = "用户不存在")
    public R<SysUserVO> detail(@RequestParam(required = true) Long userId, @RequestParam(required = false) String sex){
        return null;
    }

    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return sysUserService.info(token);
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return sysUserService.logout(token);
    }

}
